<?php

namespace App\Http\Resources\Admin;

use App\Http\Resources\BaseResource;

class UserResource extends BaseResource
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'email' => $this->email,
            'role_id' => (float) $this->role_id,
            // 关联信息
            'role' => new RoleResource($this->whenLoaded('role')),
            // 列表
            'permission_list' => $this->when( $this->showPermission, $this->permission_list),
            'created_at' => $this->created_at->format('Y-m-d H:i:s')
        ];
    }
}
